import http from "@/utils/custom_request";

// 获取盒子状态
export async function getMachineStatus(deviceId: string, deviceKey: string): Promise<any> {
    return http.get(`/device/device_info?deviceId=${deviceId}&deviceKey=${deviceKey}`);
}

// 异步刷新盒子状态
export async function asyncRefreshDeviceInfo(deviceId: string, deviceKey: string): Promise<any> {
    return http.get(`/device/async_refresh_device_info?deviceId=${deviceId}&deviceKey=${deviceKey}`);
}

// 获取打印机状态
export async function getPrinterStatus(deviceId: string, deviceKey: string, devicePort: string): Promise<any> {
    return http.get(`/device/printer_status?deviceId=${deviceId}&deviceKey=${deviceKey}&usbPort=${devicePort}`);
}

// 重启设备
export async function rebootDevice(deviceId: string, deviceKey: string): Promise<any> {
    return http.post(`/device/async_device_reboot`, {deviceId, deviceKey});
}

// 获取打印机状态
export async function getTaskStatus(deviceId: string, deviceKey: string, devicePort: string, task_id: string): Promise<API.Result> {
    return http.get(`/print/job?deviceId=${deviceId}&deviceKey=${deviceKey}&devicePort=${devicePort}&task_id=${task_id}`);
}

// 取消打印任务 Cancel printing task
export async function cancelPrintTask(deviceId: string, deviceKey: string, devicePort: string, task_id: string): Promise<any> {
    return http.delete("/print/job", {deviceId, deviceKey, devicePort, task_id});
}

// 清空打印任务
export async function clearTheTasks(deviceId: string, deviceKey: string, devicePort: string): Promise<any> {
    return http.post("/print/flush_jobs", {deviceId, deviceKey, devicePort});
}

// 上传文件
export async function uploadForm(data: any): Promise<any> {
    return http.post("/print/job", data, {
        header: {"Content-Type": "application/x-www-form-urlencoded"},
        custom: {catch: true}
    });
}

// 获取文档页数
export async function getFilePages(data: any): Promise<any> {
    return http.post("/print/file_pages", data, {
        header: {"Content-Type": "application/x-www-form-urlencoded"},
        custom: {catch: true}
    });
}


// 上传文件
// export async function newFormData(data: any): Promise<any> {
//     return http.post("/print/job", data, {header: {"Content-Type": "application/x-www-form-urlencoded"}});
// }